<?php

	class Team {
		
		public function __construct() {
		
			$this->Name = "";
			$this->PreviousName = "";
			$this->Description = "";
			$this->PreviousDescription = "";
		
		}

		function SetName($team_name) {
			$this->PreviousName = $this->Name;
			$this->Name = strtoupper(substr($team_name,0,50));
		}

		function SetDescription($team_description) {
			$this->PreviousDescription = $this->Description;
			$this->Description = strtoupper(substr($team_description,0,50));
		}
		
		public function GetName() {
			return $this->Name;
		}

		public function GetDescription() {
			return $this->Description;
		}

		function Load($team_name) {
		
			global $db_host, $db_username, $db_password, $db_database;
			
			$team_name = strtoupper(substr($team_name,0,50));
	
			mysql_connect($db_host,$db_username,$db_password);
			@mysql_select_db($db_database) or die("Unable to select database");
			$db_query = "SELECT * FROM team WHERE team_name = '$team_name';";
			$db_result = mysql_query($db_query);
			$db_count = mysql_num_rows($db_result);
			mysql_close();	
			
			if($db_count>0) {
			
				$team_name				= mysql_result($db_result,0,"team_name");
				$team_description		= mysql_result($db_result,0,"team_description");
				
				$this->Name = strtoupper($team_name);
				$this->Description = $team_description;	
				
				return true;			
	
			} else {
			
				$this->Name = "";
				$this->Description = "";
				
				return false;
				
			}
		
		}
		
		function Save() {
		
			global $db_host, $db_username, $db_password, $db_database;
			
			$team_name = $this->Name;
			$team_description = $this->Description;
			$team_previous_name = $this->PreviousName;
			
			$team_name = strtoupper(substr($team_name,0,50));
			$team_description = substr($team_description,0,255);			
					
			mysql_connect($db_host,$db_username,$db_password);
			mysql_select_db($db_database) or die("Unable to select database");
			
			$db_query = "SELECT * FROM team WHERE team_name = '$team_previous_name';";
			$db_result = mysql_query($db_query);
			$db_count = mysql_num_rows($db_result);
			
			if($db_count==0) {
				
				$db_query = "INSERT INTO team VALUES ('$team_name','$team_description');";
				mysql_query($db_query);
				
			} else {
			
				$db_query = "UPDATE team SET team_name = '$team_name', team_description = '$team_description' WHERE team_name = '$team_previous_name';";
				mysql_query($db_query);
			
			}
			
			mysql_close();
		
		}

		function Delete() {
		
			global $db_host, $db_username, $db_password, $db_database;
			
			$team_name = $this->Name;			
					
			mysql_connect($db_host,$db_username,$db_password);
			mysql_select_db($db_database) or die("Unable to select database");
			$db_query = "DELETE FROM team WHERE team_name = '$team_name';";
			mysql_query($db_query);
			mysql_close();
		
		}
		
	
	}

?>
